import {BasicColumn, FormSchema} from '@/components/Table';
import {Switch} from "ant-design-vue";
import {getPostsAndRoles} from "@/api/system/user";



export const columns: BasicColumn[] = [
  {
    title: '用户编号',
    dataIndex: 'userId',
    width: 120,
  },
  {
    title: '用户名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '昵称',
    dataIndex: 'nickName',
    width: 120,
  },
  {
    title: '所属部门',
    dataIndex: 'dept',
    customRender: ({value}) => {
      let deptName: String = value.deptName
      return deptName;
    },
  },
  {
    title: '手机号码',
    dataIndex: 'phonenumber',
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({record}) => {
      return (
        <Switch checked={record.status === '0'}/>
      );
    },
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '用户名称',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    field: 'phonenumber',
    label: '手机号码',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    //时间
    field: '[params.beginTime,params.endTime]',
    label: "创建时间",
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: ["开始时间", "结束时间"],
      valueFormat:'YYYY-MM-DD'
    },
    colProps: { span: 12 },
  },
];




export const resetPwdFromSchema: FormSchema[] = [
  {
    field: 'password',
    label: '用户密码',
    component: 'InputPassword',
    required: true,
  },
]

export const accountFormSchema: FormSchema[] = [
  {
    field: 'nickName',
    label: '用户昵称',
    component: 'Input',
    required: true,
  },
  {
    field: 'deptId',
    label: '部门',
    component: "TreeSelect",
    componentProps: {
      fieldNames:{
        value:"id"
      },
      showSearch: true,// 开启搜索
      treeNodeFilterProp:'label', //一定要加
      placeholder:'输入关键字可搜索'
    },
  },
  {
    field: 'phonenumber',
    label: '手机号码',
    component: 'Input',
  },
  {
    field: 'email',
    label: '邮箱',
    component: 'Input',
  },
  {
    field: 'userName',
    label: '用户名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'password',
    label: '用户密码',
    component: 'InputPassword',
    required: true,
  },
  {
    field: 'sex',
    label: '用户性别',
    component: 'DictTree',
    componentProps:{
      params:{
        dictType:"sys_user_sex"
      }
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'DictTree',
    componentProps:{
      params:{
        dictType:"sys_normal_disable"
      }
    },
  },
  {
    field: "postIds",
    label: "岗位",
    component: "ApiSelect",
    componentProps: {
      params:{
        id:""
      },
      mode:"multiple",
      showSearch: true, // 开启搜索
      api: getPostsAndRoles,
      resultField:'posts',
      immediate:true,
      labelField: 'postName',
      valueField: 'postId',
      optionFilterProp:'postName', // 搜索按label字段搜索
    },
  },
  {
    field: "roleIds",
    label: "角色",
    component: "ApiSelect",
    componentProps: {
      params:{
        id:""
      },
      mode:"multiple",
      showSearch: true, // 开启搜索
      api: getPostsAndRoles,
      resultField:'roles',
      immediate:true,
      labelField: 'roleName',
      valueField: 'roleId',
      optionFilterProp:'roleName', // 搜索按label字段搜索
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
  }
];
